/*
 * @Author: wz
 * @Date: 2020-11-30 15:13:01
 * @LastEditors: wz
 * @LastEditTime: 2020-12-08 00:01:40
 * @Description: keepAlive 缓存页面
 */

const state = {
    keepAliveList: [] // 缓存页面的$route.name
}
const getters = {
    keepAliveList: state => state.keepAliveList
}
const mutations = {
    /**
     * @description:  更新缓存页面列表
     * @param {*} state
     * @param {*} data
     * @return {*}
     */
    updateKeepAliveList(state, data) {
        let { name, type = 'push' } = data
        console.log(name, type)
        let index = state.keepAliveList.findIndex(item => item == name)
        if (type == 'push' && index < 0) {
            state.keepAliveList.push(name)
        }
        if (type == 'delete' && index >= 0) {
            state.keepAliveList.splice(index, 1)
        }
        if (type == 'clear') {
            state.keepAliveList = []
        }
    }
}
export default { state, getters, mutations }
